<?php
/**
 * AdminNavigation.php
 *
 * @category    Madoqua
 * @package     View
 * @subpackage  Helper
 */

/** base class */
require_once 'Madoqua/View/Helper/Abstract.php';

/**
 * Madoqua_View_Helper_AdminNavigation
 *
 * @category    Madoqua
 * @package     View
 * @subpackage  Helper
 */
class Madoqua_View_Helper_AdminNavigation extends Madoqua_View_Helper_Abstract
{
    /**
     * active section
     *
     * @var string
     */
    protected $_section;

    /**
     * active action
     *
     * @var string
     */
    protected $_active;

    /**
     * constructor like function, chains to itself
     *
     * @param string $section
     * @param string $active
     * @return Madoqua_View_Helper_AdminNavigation
     */
    public function adminNavigation($section = null, $active = null, $reset = false)
    {
        if ($reset) {
            unset($this->_active);
            unset($this->_section);
        }
        //reset

        if ($section !== null && empty($this->_section)) {
            $this->_section = $section;
        }
        if ($active != null && empty($this->_active)) {
            $this->_active = $active;
        }
        //set

        return $this;
    }

    /**
     * string-i-fy!
     *
     * @return string
     */
    public function __toString()
    {
        if ($this->hasActive()) {
            return $this->partial('admin/partials/navigation_' . $this->_section . '.phtml');
        } else {
            return '';
        }
    }

    /**
     * get html class for active
     *
     * @param string $action
     * @return string
     */
    public function getClass($action)
    {
        $class = $this->_section . '-' . $action;
        if ($action == $this->_active) {
            return 'class="active ' . $class . '"';
        } else {
            return 'class="' . $class . '"';
        }
    }

    /**
     * get active class for menu
     *
     * @param string $section
     * @return string
     */
    public function getMenuClass($section) {
        if ($section == $this->_section) {
            return 'class="active"';
        }
    }

    /**
     * is the helper set up?
     */
    public function hasActive()
    {
        return (!empty($this->_section) && !empty($this->_active));
    }

    /**
     * get active section
     *
     * @return string
     */
    public function getSection()
    {
        return $this->_section;
    }

    /**
     * get active action
     *
     * @return string
     */
    public function getActive()
    {
        return $this->_active;
    }
}